﻿<ResourceDictionary
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
  xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
  xmlns:wu="clr-namespace:Monogram.WpfUtils"
  mc:Ignorable="d" >

  <ControlTemplate  TargetType="{x:Type wu:DetailsView}" x:Key="{x:Static wu:DetailsView.DETAILSVIEW_TEMPALATE_KEY}">
    <Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Padding="{TemplateBinding Padding}" 
                  HorizontalAlignment="{TemplateBinding HorizontalAlignment}" VerticalAlignment="{TemplateBinding VerticalAlignment}" >
      <Grid Name="PART_LayoutGrid">
        <Grid.ColumnDefinitions>
          <ColumnDefinition Width="auto"  />
          <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>
      </Grid>
    </Border>
  </ControlTemplate>

  <Style TargetType="{x:Type wu:DetailsView}">
    <Style.Resources>
      <DataTemplate x:Key="DV_HeaderTemplate">
        <Label Content="{Binding Header}" HorizontalAlignment="Right" Padding="2"  />
      </DataTemplate>


      <DataTemplate x:Key="DV_FieldTemplate">
        <TextBlock Name="PART_Content" wu:DetailsView.BindProperty="{x:Static TextBlock.TextProperty}" HorizontalAlignment="Stretch"  TextWrapping="Wrap" Margin="2" />
      </DataTemplate>

      <DataTemplate x:Key="DV_FieldTemplate_Edit">
        <TextBox Name="PART_Content" wu:DetailsView.BindProperty="{x:Static TextBox.TextProperty}" HorizontalAlignment="Stretch" Margin="2" />
      </DataTemplate>

      <DataTemplate x:Key="DV_EnumFieldTemplate">
        <TextBlock Name="PART_Content" HorizontalAlignment="Stretch" Margin="2" 
                 Text="{Binding Converter={x:Static wu:EnumToFriendlyNameConverter.Instance}}"  />
      </DataTemplate>

      <DataTemplate x:Key="DV_EnumFieldTemplate_Edit">
        <ComboBox wu:Attached.ItemsSourceFromEnum="true"
          SelectedItem="{Binding DataContext, RelativeSource={RelativeSource Self}}"
          >
          <ComboBox.ItemTemplate>
            <DataTemplate>
              <TextBlock Text="{Binding Converter={x:Static wu:EnumToFriendlyNameConverter.Instance}}" />
            </DataTemplate>
          </ComboBox.ItemTemplate>
        </ComboBox>
      </DataTemplate>

      <DataTemplate x:Key="DV_EnumerableFieldTemplate">
        <ItemsControl  Margin="2" wu:DetailsView.BindProperty="{x:Static ItemsControl.ItemsSourceProperty}" />
      </DataTemplate>

      <DataTemplate x:Key="DV_EnumerableFieldTemplate_Edit">
        <ItemsControl  Margin="2" wu:DetailsView.BindProperty="{x:Static ItemsControl.ItemsSourceProperty}" />
      </DataTemplate>
      

      <DataTemplate x:Key="DV_MultilineFieldTemplate_Edit">
        <TextBox Name="PART_Content" wu:DetailsView.BindProperty="{x:Static TextBox.TextProperty}" HorizontalAlignment="Stretch" AcceptsReturn="True" VerticalAlignment="Stretch" Margin="2"
               VerticalScrollBarVisibility="Auto" TextWrapping="Wrap"
               />
      </DataTemplate>

      <DataTemplate x:Key="DV_BooleanFieldTemplate_Edit">
        <CheckBox Name="PART_Content" wu:DetailsView.BindProperty="{x:Static CheckBox.IsCheckedProperty}" VerticalAlignment="Center" Margin="2"   />
      </DataTemplate>
    </Style.Resources>

    <Setter Property="Template"  Value="{StaticResource {x:Static wu:DetailsView.DETAILSVIEW_TEMPALATE_KEY}}" />
    <Style.Triggers>
      <Trigger Property="DataContext" Value="{x:Null}">
        <Setter Property="Template" Value="{x:Null}"/>
      </Trigger>
    </Style.Triggers>
  </Style>




</ResourceDictionary>
